﻿@model S4Store.Models.AfterSaleReport.SparePartModel
@{
    ViewBag.Title = "ZKTS";
    Layout = null;
}
@{
    var curMonthConfig = Model.MonthConfig.FirstOrDefault();
    if (curMonthConfig == null)
    {
        curMonthConfig = new S4Store.Domain.AfterSaleKpi.SparePartsMonthInput();
    }

    List<dynamic> list = new List<dynamic>();
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {
        var query = Model.MonthConfigs.Where(o => o.Month.Year == dt.Year && o.Month.Month == dt.Month).FirstOrDefault();
        if (query == null)
        {
            list.Add(new
            {
                时间 = dt,
                目标在库天数 = 0,
                实际在库天数 = 0
            });
        }
        else
        {
            list.Add(new
            {
                时间 = dt,
                目标在库天数 = query.PJZKTSMB,
                实际在库天数 = Model.PJZKTS(dt.Year, dt.Month)
            });
        }
    }

    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.YAxis = "天数";
    ChartModel.IsRate = false;


    foreach (var item in list.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "目标在库天数";
    foreach (var item in list)
    {
        series.Data.Add(item.目标在库天数);
    }
    ChartModel.Serieses.Add(series);
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "实际在库天数";
    foreach (var item in list)
    {
        series1.Data.Add(item.实际在库天数);
    }
    ChartModel.Serieses.Add(series1);

    Model.MonthConfigs = Model.MonthConfig;
}
<div style="height: 100%; overflow: auto">
    @Html.Action("ReportBar", "Common", Model.BarModel)
    <div style="position: relative; width: 100%">
        <div class="pagetitle">备件库存管理关键KPI</div>
        <table width="100%">
            <tr>
                <td style="width:5%">
                    &nbsp;
                </td>
                <td valign="top" style="width:15%">
                    <table class="reporttable" style="border-collapse: collapse;">
                        <thead>
                            <tr>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        执行月度</div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        库    存    成   本   总   量


                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        日    均   备   件   销   售   成   本


                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        平          均         在       库       天          数
                                    </div>
                                </th>
                            </tr>
                        </thead>
                        <tr>
                            <td>@curMonthConfig.Month.Month</td>
                            <td>@curMonthConfig.KCCBZL</td>
                            <td>@curMonthConfig.RJBJXSCB</td>
                            <td @if (Model.PJZKTS(Model.BarModel.Month.Year, Model.BarModel.Month.Month) > curMonthConfig.PJZKTSMB)
                                    {
                                    <text> style="background:#ff1100"</text>
                                    }>@Model.PJZKTS(Model.BarModel.Month.Year, Model.BarModel.Month.Month)</td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                考核目标
                            </td>
                            <td>
                                @(curMonthConfig.PJZKTSMB)
                            </td>
                        </tr>
                    </table>
                </td>
                <td  style="width:80%">
                    @Html.Partial("../Chart/Line", ChartModel)
                </td>
            </tr>
        </table>
    </div>
</div>
